<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}

			#myCan {
				display: block;
				margin: 0 auto;
				background-color: lightskyblue;
			}
		</style>
	</head>
	<body>
		<canvas id="myCan" width="400" height="400"></canvas>
		<script type="text/javascript">
			var oC = document.getElementById('myCan');
			var ctx = oC.getContext('2d');
			ctx.fillStyle = 'red';	
			ctx.fillRect(50,50,100,100);
			//获取矩形区域的像素点
			var oImg = ctx.getImageData(50,50,100,100);
			console.log(oImg.data);

			//设置像素区域
			oImg.data[4] = 0;
			oImg.data[5] = 255;
			oImg.data[6] = 0;
			oImg.data[7] = 255;
			
			// oImg.data[19800] = 0;
			// oImg.data[19801] = 0;
			// oImg.data[19802] = 255;
			// oImg.data[19803] = 255;
			for(var i=400;i<500;i++){
				oImg.data[4*i] = 255;
				oImg.data[4*i+1] = 255;
				oImg.data[4*i+2] = 0;
				oImg.data[4*i+3] = 255;
			}
			ctx.putImageData(oImg,200,200);
		</script>
	</body>
</html>